package com.situ.controller;

import com.github.pagehelper.PageInfo;
import com.situ.api.CommonResult;
import com.situ.entity.SalChance;
import com.situ.service.SalChanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * SalChance的路由接口服务
 * 
 * @author胡文
 *
 */
//
@Api(description = "SalChance模块接口说明")
@RestController
@CrossOrigin //跨域注解
public class SalChanceController {

	/** SalChanceService服务 */
	@Autowired
	private SalChanceService salChanceService;
	
	/**
	 * 查询所有SalChance数据的方法
	 * @param value
	 * @return
	 */
@ApiOperation("查询所有SalChance数据的方法")
	@GetMapping(value = "/SalChance/query", produces = {"application/json;charset=UTF-8"})
	public CommonResult query(SalChance value) {
	List<SalChance> list = salChanceService.find(value);
		return CommonResult.success(list);
	}
	
//	/**
//	 * 通过id查询SalChance数据的方法
//	 *
//	 * @return
//	 */
//     @ApiOperation("通过id查询SalChance数据的方法")
//	@GetMapping(value = "/SalChance/queryById/{id}", produces = {"application/json;charset=UTF-8"})
//	public ResponseData queryById(@PathVariable(name="id") Long id) {
//		 return ResponseData.ok().putDataValue("obj",salChanceService.findOne(id));
//	}
//
//	/**
//	 * 插入SalChance属性不为空的数据方法
//	 *
//	 * @return
//	 */
@ApiOperation("插入SalChance属性不为空的数据方法")
	@PostMapping(value = "/SalChance/save")
	public CommonResult save(SalChance sales) {
		SalChance rows = salChanceService.saveNotNull(sales);

		return CommonResult.success(rows);
	}

	/**
	 * 更新SalChance属性不为空的数据方法
	 *
	 * @return
	 */
     @ApiOperation("更新SalChance属性不为空的数据方法")
	@PostMapping(value = "/SalChance/update", produces = {"application/json;charset=UTF-8"})
	public CommonResult update(SalChance sales) {
		int rows =  salChanceService.updateNotNullById(sales);
		return CommonResult.success(rows);
	}

	/**
	 * 更新SalChance属性不为空的数据方法
	 *
	 * @return
	 */
	@ApiOperation("更新SalChance属性不为空的数据方法")
	@PostMapping(value = "/SalChance/editSales", produces = {"application/json;charset=UTF-8"})
	public CommonResult editSales(SalChance sales) {
		int rows =  salChanceService.updateSalChance(sales);
		return CommonResult.success(rows);
	}
//
//	/**
//	 * 通过id删除SalChance数据方法
//	 *
//	 * @return
//	 */
//     @ApiOperation("通过id删除SalChance数据方法")
//	@PostMapping(value = "/SalChance/delById/{id}", produces = {"application/json;charset=UTF-8"})
//	public ResponseData delById(@PathVariable(name="id") Long id) {
//		return ResponseData.ok().putDataValue("obj",salChanceService.deleteById(id));
//	}


    //带分页的查询全部
    @ApiOperation("带分页的条件模糊查询")
    @GetMapping(value = "/SalChance/queryPage", produces = {"application/json;charset=UTF-8"})
    public CommonResult queryPage(String chc_cust_name,String chc_title,String chc_linkman,
								  @ApiParam("第几页")
								  @PathParam("pageNum") int pageNum ,
								  @ApiParam("每页多少条")
								  @PathParam("pageSize") int pageSize) {
		PageInfo<SalChance> list = salChanceService.find2(chc_cust_name,chc_title,chc_linkman,pageNum,pageSize);
        return CommonResult.success(list);
   }

}
